<?php

declare(strict_types=1);
/**
 * This file is part of MoChat.
 * @link     https://mo.chat
 * @document https://mochat.wiki
 * @contact  group@mo.chat
 * @license  https://github.com/mochat-cloud/mochat/blob/master/LICENSE
 */
namespace MoChat\App\Utils;

use Qbhy\HyperfAuth\AuthManager;
use Qbhy\SimpleJwt\JWTManager;

class Str
{
    /**
     * 生成密码
     */
    public static function generateSignaturePassword(string $password = '', string $guardName = 'jwt'): string
    {
        $authManager = make(AuthManager::class);
        $guard = $authManager->guard($guardName);

        if (empty($password)) {
            $password = substr(md5(mt_rand(0, 32) . '0905' . md5((string) mt_rand(0, 32)) . '0123'), 10, 6);
        }
        /** @var JWTManager $jwt */
        $jwt = $guard->getJwtManager();
        return $jwt->getEncrypter()->signature($password);
    }
}
